<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<!-- <view class="action bg-white "
			style="padding: 15px 0 0 10px;font-size: 20px;align-items: center;display: flex;">
			<u-icon name="/static/image/invcode.png" size="80"></u-icon>
			<text class="cuIcon-titles text-bold">废旧物资信息</text>
		</view> -->

		<u-form class="form bg-white" :model="model" ref="uForm" label-position="left">
			<u-form-item label="单据号:" prop="ccode" label-width="220" >
				<u-input placeholder=" " v-model="model.ccode" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="单据日期:" prop="ddate" label-width="220" >
				<u-input placeholder=" " v-model="model.ddate" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="出库类别(原):" prop="crdName" label-width="220">
				<u-input placeholder=" " v-model="model.crdName" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="领用部门(原):" prop="cdefine23" label-width="220" >
				<u-input placeholder=" " v-model="model.depName" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="出库类别(新):" prop="invCode2" label-width="220" :label-style="{'font-weight':'bold'}">
				<js-select v-model="model.crdCode2" :showFilter="false" :items="rdStyleList" placeholder="请选择" :tree="true"
					:label-value="model.crdName2" @label-input="model.crdName2 = $event" @input="model.crdCode2 = $event" 
					itemValue="id" itemLabel="name"></js-select>
			</u-form-item>	
			<u-form-item label="领用部门(新):" prop="invName2" label-width="220" :label-style="{'font-weight':'bold'}">
				<js-select v-model="model.depCode2" :showFilter="false" :items="OfficeList" placeholder="请选择" :tree="true"
					:label-value="model.depName2" @label-input="model.depName2 = $event" @input="model.depCode2 = $event"
					itemValue="id" 
					></js-select>
			</u-form-item>	
		</u-form>
		
	<view style="height: 70px;"></view>
	<view class=" flex cu-bar tabbar bg-white foot cu-modal-footer">
		<button class="cu-btn  lines-red lg" @click="cancel">关闭</button>
		<button class="cu-btn  bg-confirm lg  margin-left" @click="submit">保存</button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				model: {
					// id:'',
					// carNo:'',
					// planDate:'',
					// cdriver:'',
					// driverPhone:'',
					// carVenCode:'',
					// carVenName:'',
					// remarks:'',
				},
				//主表id
				query: {
					id: '',
				},
				//子表id
				querys: {
					id: '',
				},
				children: [],
				carVenSelectList: [],
				OfficeList:[],
				pickerTime: false, //控制日期显示
				rdStyleList:[]
			}
		},
		onLoad(params) {
			this.model = JSON.parse(params.item)
			// if(params.id){
			// 	this.query.id = params.id
			// 	this.$u.api.mf.fjform(this.query).then(res => {
			// 		this.model = res.mfCarplanFjH;
			// 	});
			// }
			this.getOfficeListData()
			this.getrdStyleTreeData()
			// uni.$on('chObj', (data) => {
			// 	this.model.invCode2 = data.invCode
			// 	this.model.invName2 = data.invName
			// 	this.model.invStd2 = data.invStd
			// 	this.$forceUpdate()
			// })
		},
		onShow() {},
		onReady() {
			// 运输单位数据
			// this.$u.api.mf.posTreeData().then(res => {
			// 	this.carVenSelectList = res;
			// });
		},
		methods: {
			// 
			getOfficeListData() {
				this.$u.api.office.treeData({
					isAll:true
				}).then(res => {
					
					// this.OfficeList = res
					this.OfficeList = res.filter(item => item.id !== "MFHG");
				})
			},
			getrdStyleTreeData(){
				this.$u.api.mf.rdStyleTreeData({
					// excludeCode: this.model.id,
					brdFlag:0,
					isShowCode:true
				}).then(res => {
					this.rdStyleList = res
				})
			},
			xzch(){
				uni.navigateTo({
					url: '/pages/mf/llsq/chXz',
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						Filter(data) {
							console.log(data)
						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						//res.eventChannel.emit('initfilter', that.queryData)
					}
				})
			},
			carNoconfirm(v){
				this.model.carNo = v;
				this.$forceUpdate()
			},
			showKeyboard(ref){
				this.$refs[ref].toShow(this.model.carNo)
			},
			cancel() {
				// uni.$emit('refreshData');
				uni.navigateBack({
					delta: 1,
				})
			},
			toFindDetail(model) {
				const that = this
				uni.navigateTo({
					url: '/pages/mf/fh/fhDetailList?hid=' + model.id,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						Filter(data) {

						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						// res.eventChannel.emit('initfilter', that.filter)
					}
				})
			},
			toAddDetail(model) {
				const that = this
				uni.navigateTo({
					url: '/pages/mf/fh/fhHwAdd?hid=' + model.id,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						Filter(data) {

						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						// res.eventChannel.emit('initfilter', that.filter)
					}
				})
			},
			delDetail(id) {
				this.querys.id = id;
				uni.showModal({
					title: '删除提示',
					content: '是否删除此详情？',
					confirmColor: '#F54E40',
					success: (res) => {
						if (!res.confirm) {
							this.isdisabled = true
							return false;
						}
						this.$u.api.mf.fjdelDetail(this.querys).then(res => {
							if (res.result=="true") {
								this.$u.toast("删除成功！");
							} else {
								this.$refs.jsError.showError('',res.message,'error');
							}
							this.querys.id = ''
							this.loadList();
						})
					}
				})
			},
			editDetail(item){
				const that=this
				uni.navigateTo({
				  url: '/pages/mf/fjwz/detailForm?model='+JSON.stringify(item),
				  events: {
				    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
				    Filter(data) {
						
				    }
				  },
				  success: function(res) {
				    // 通过eventChannel向被打开页面传送数据
				    // res.eventChannel.emit('initfilter', that.filter)
				  }
				})
			},
			loadList() {
				this.$u.api.mf.fjfindList(this.query).then(res => {
					if (!res.list || res.list.length == 0) {
						return;
					}
					var data = res.list[0];
					this.model = data;
					this.children = data.mfCarplanFjCList;
				})
			},
			GoaddChild() {
				if (this.model.id == null || this.model.id == '') {
					this.$refs.jsError.showError('','请先保存废旧物资信息！','error');
					return;
				} else {
					const that = this;
					uni.navigateTo({
						url: '/pages/mf/fjwz/detailForm?model=' + JSON.stringify({id:this.model.id}),
						events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							Filter(data) {
								console.log(data)
							}
						},
						success: function(res) {
							// 通过eventChannel向被打开页面传送数据
							//res.eventChannel.emit('initfilter', that.queryData)
						}
					})
				}
			},
			timeConfirm(e) {
				this.model.planDate = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ":" + e.minute + ":" + e
					.second;
			},
			submit(data, callback) {
				if((this.model.crdCode2 == null || this.model.crdCode2 == '') && (this.model.depCode2 == null || this.model.depCode2 == '')){
					this.$refs.jsError.showError('','请选择出库类别或者领用部门！','error');
					return;
				}else{
					let data = {
						id:this.model.id,
						// invCode:this.model.invCode2,
					};
					this.model.crdCode2 ? data.crdCode = this.model.crdCode2 : ''
					this.model.depCode2 ? data.depCode = this.model.depCode2 : ''
					this.$u.api.mf.updateHeadInfo(data).then(res => {
						if(res.result == 'true'){
							this.$u.toast(res.message);
							uni.navigateBack({
								delta: 1
							})
						}else{
							this.$refs.jsError.showError('',res.message,'error');
						}
					});
				}
			},
		}
	}
</script>
<style lang="less">
	/* .footer {
	position: fixed;
	bottom: 0;
	right:0;
	width: 100%;
	line-height: var(--footer-height);
	background: #ffffff;
	color: #ffffff;
} */
	.btn-plus {
		position: fixed;
		bottom: 260rpx;
		right: 40rpx;
		z-index: 2;
		opacity: 0.6;
	}

	.btn-plus:hover {
		opacity: 1;
	}

	.add {
		position: absolute;
		right: 130rpx;
		top: 0;
		margin-right: 0;
	}

	.upload {
		position: absolute;
		right: 65rpx;
		top: 0;
		margin-right: 0;
	}

	.rights {
		position: absolute;
		/* display: inline-block; */
		right: 0;
		top: 0;
		margin-right: 0;
		/* width: 100%; */

	}

	.cu-bar {
		min-height: 80px;
	}

	.cu-btn {
		font-size: 16px;
		height: 40px;
	}

	.foot {
		background: #fff;
	}

	.cu-item {
		flex-wrap: wrap;
		padding: 8px 15px !important;
	}

	.title {
		width: 230rpx;
	}

	.cu-modal-slot {
		margin: 42rpx 32rpx 20rpx 32rpx;
		height: 100vh;
		position: relative;
	}

	.cu-modal-header {
		font-size: 38rpx;
		color: #3d3d3d;
		line-height: 40rpx;
		text-align: left;
		font-weight: 500;
	}

	.button {
		font-size: 32rpx;
		color: #666666;
		line-height: 40rpx;
		padding: 12rpx 40rpx;
		margin-bottom: 20rpx;
		background: #e2e2e2;
		border-radius: 180rpx;
	}

	.button:hover {
		background: #3e97b0;
		color: #ffffff;
	}

	.cu-modal-search-title {
		margin: 32rpx 0rpx 20rpx 0rpx;
		text-align: left;
		font-size: 32rpx;
		color: #999999;
		line-height: 40rpx;
	}

	.cu-dialog {
		background: #ffffff;
	}

	.cu-modal-footer {
		padding: 32rpx 32rpx !important;
		width: 100%;

		.cu-btn {
			width: 50%;
		}
	}

	.bg-confirm {
		background: #3e97b0;
		color: #ffffff;
	}
</style>